﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.ComponentModel.Composition;

namespace Steve.UI
{
    public abstract class RewriterBase
    {
        [Import]
        public SiteExplorerRepository SiteExplorer { get; set; }

        public abstract RewriteResult Rewrite(Uri requestUrl, UrlObject match);

        public RewriteResult Rewrite(Uri requestUrl)
        {
            var lazy = SiteExplorer.NavigateTo(requestUrl);

            if (lazy == null) return Rewrite(requestUrl, null);

            return Rewrite(requestUrl, lazy.Value);
        }
    }
}
